package com.henry.chatkit.messages.holder

import android.view.View
import android.widget.TextView
import com.henry.chatkit.messages.MessageInfo
import com.henry.chatkit.R

class MessageTextHolder(itemView: View) : MessageContentHolder(itemView) {

    private lateinit var msgBodyText: TextView

    override fun getVariableLayout(): Int {
        return R.layout.message_content_text
    }

    override fun initVariableViews() {
        msgBodyText = rootView.findViewById(R.id.msg_body_tv)
        msgBodyText.maxWidth = properties.textMaxWidth
    }

    override fun layoutVariableViews(msg: MessageInfo?, position: Int) {

        if (msg == null) {
            return
        }

        msgBodyText.visibility = View.VISIBLE
        msgBodyText.text = msg.text.trim()

        if (properties.chatContextFontSize != 0) {
            msgBodyText.textSize = properties.chatContextFontSize.toFloat()
        }
        if (msg.isSelf) {
            if (properties.rightChatContentFontColor != 0) {
                msgBodyText.setTextColor(properties.rightChatContentFontColor)
            }
        } else {
            if (properties.leftChatContentFontColor != 0) {
                msgBodyText.setTextColor(properties.leftChatContentFontColor)
            }
        }
    }
}